<template>
  <div class="airoom">
    <div class='chat-header'>
      <h1>Online：（{{Chat.onlineCount}}）</h1>
      <div class='gotoroom' @click='gotoroom'>回去和大家聊天吧</div>
      <group-info-body></group-info-body>
    </div>
    <ai-body></ai-body>
    <div class="foot-wrapper">
      <div class='foot-tool'>
      </div>
      <textarea id='txt' class="chat-input" type="text" name="" @keyup.ctrl.enter="send(msg)" v-model="msg" placeholder="说点啥嘛"></textarea>
      <span class="chat-sub" :class="{'primary':!!msg}"  @click="send(msg)" type='button'>发送</span><span class='ts'>ctrl+enter</span>
    </div>
  </div>
</template>

<script>
import Chat from '../api/client'
import GroupInfoBody from './GroupInfoBody'
import AiBody from './AiBody'
export default {
  data () {
    return {
      msg: '',
      Chat: Chat,
      div: null
    }
  },
  mounted () {
    this.$nextTick(function () {
      if (!localStorage.getItem('name')) {
        this.$router.go('/login')
      }
      Chat.init()
    })
  },
  beforeCreate () {
    // 获取参数
    var iss = this.$route.query.refresh
    if (iss) {
      // 跳转
      this.$router.push({path: '/ai'})
      // 刷新，为啥要刷新，因为有bug
      window.location.reload()
    }
  },
  components: {
    GroupInfoBody, AiBody
  },
  methods: {
    gotoroom () {
      this.$router.push({path: '/room', query: {refresh: true}})
    },
    send (msg) {
      Chat.aiSubmit(msg)
      this.msg = ''
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .gotoroom{
    height:40px;
    text-align: center;
    margin:10px 0 5px;
    line-height:40px;
    color:#fff;
    background: -webkit-linear-gradient(left top, #00cccc , #3CAF36);
    background: -o-linear-gradient(top right, #00cccc, #3CAF36);
    background: -moz-linear-gradient(top right, #00cccc, #3CAF36);
    background: linear-gradient(to top right, #00cccc , #3CAF36);
  }
  .airoom{
    position:absolute;
    top:0;
    left:0;bottom:0;right:0;
    background: -webkit-linear-gradient(left top, #F0F4F7 , #CBE0F1);
    background: -o-linear-gradient(top right, #F0F4F7, #CBE0F1);
    background: -moz-linear-gradient(top right, #F0F4F7, #CBE0F1);
    background: linear-gradient(to top right, #F0F4F7 , #CFEFFF);
  }
  .chat-header{
    position:absolute;
    background:#FFF;
    width:23%;
    top:50px;
    bottom:50px;
    left:5%;
  }
  .chat-header h1{
    text-align:center;
    font-size:14px;
    font-weight:normal;
    line-height:20px;
    padding:2% 0;
    border-bottom:1px solid #ccc;
  }
  .foot-wrapper{
    position:absolute;
    background:#FFF;
    width:65%;
    right:5%;
    bottom:50px;
    height:150px;
  }
  .foot-tool{
    height:40px;
    line-height:40px;
    position:relative;
    border-bottom:1px solid #eee;
  }
  input,textarea{
    outline:none;
  }
  .chat-input{
    display: block;
    border:0 none;
    height:50px;
    width:98%;
    resize:none;
    padding:10px 1%;
    background:none;
  }
  .chat-sub{
    line-height:30px;
    border:1px solid #666;
    padding:0 30px;
    border-radius: 5px;
    float:right;
    margin:0 20px 0 0;
    cursor:pointer;
  }
  .ts{
    float:right;
    line-height:32px;font-size:12px;color:#ccc;padding-right:10px;
  }
  .emoji-display {
    position: absolute;
    width: 100%;
    height: 210px;
    top: -210px;
    left: 0;
    overflow-y: auto;
    background:#fff;
  }
  ul {
    display: flex;
    flex-wrap: wrap;
    list-style-type:none;
  }
  li {
    list-style-type:none;
    padding: 2px 3px;
    font-size: 2em;
    color:#000;
    float:left;
    cursor:pointer;
  }
  .chat-body{
    overflow:auto;
    position:absolute;
    top:50px;
    bottom:220px;
    width:61%;
    padding:2%;
    right:5%;
    background:#fff;
  }
  .chat-box{
    position:absolute;
    top:50px;
    bottom:0;
    overflow-y:hidden;
  }
  .chat-body h1{
    text-align:center;
    font-size:18px;
    border-bottom:1px solid red;
  }
  .self-wrap{
    overflow:hidden;
    padding:20px 5px;
    overflow:hidden;
  }
  .self-wrap .header,
  .self-wrap .msg{
    display:block;
    float:right;
    line-height:1.5;
  }
  .self-wrap .time{
    text-align:right;
    font-size:12px;
    color:#999;
    margin-bottom:10px;
  }
  .self-wrap .msg{
    max-width:66%;
    background:#3598DB;
    color:#fff;
    margin-right:10px;
    padding:10px 20px;
    border-top-left-radius:35px;
    border-bottom-right-radius:35px;
    border-top-right-radius:10px;
    border-bottom-left-radius:10px;
  }
</style>
